package Test;

import DB.CustomerDB;
import DB.SalesOrderDB;
import Model.*;
import org.junit.Test;
import static org.junit.Assert.fail;
public class SalesOrderDBTest {

    @Test
    public void testFindSalesOrder() throws Exception {
        SalesOrderDB salesOrderDB = new SalesOrderDB();

        SalesOrder salesOrder = new SalesOrder(1, "Date", "Test", "Test");
        salesOrderDB.insertSalesOrder(salesOrder);

        int find = 5;

        SalesOrder sales = salesOrderDB.findSalesOrder(find);

        if (sales != null){
            System.out.println(
                  sales.getId() + " " +
                  sales.getDate() + " " +
                  sales.getTotalPrice() + " " +
                  sales.getDeliveryStatus() + " " +
                  sales.getDeliveryDate() + " " +
                  sales.getCustomer());

        }
        else {
            fail("Salesorder couldnt be found - Failure");
        }


    }

    @Test
    public void testInsertSalesOrder() throws Exception {
        SalesOrderDB salesOrderDB = new SalesOrderDB();
        int rc = salesOrderDB.insertSalesOrder(new SalesOrder(1, "Date", "Test", "Test"));

        System.out.println(rc);

        if (rc == 1) {
            System.out.println("Inserting salesOrder successful");
        }
        else {
            fail("Failed inserting salesOrder");
        }
    }

    @Test
    public void testUpdateSalesOrder() throws Exception {

    }

    @Test
    public void testDeleteSalesOrder() throws Exception {
        SalesOrderDB salesOrderDB = new SalesOrderDB();

        SalesOrder salesOrder = new SalesOrder(1, "Date", "Test", "Test");
        salesOrderDB.insertSalesOrder(salesOrder);

        if (salesOrderDB.findSalesOrder(50) != null) {
            salesOrderDB.deleteSalesOrder(50);

            if (salesOrderDB.findSalesOrder(50) == null) {
                System.out.println("Delete successful");
            }
            else {
                fail("Delete not successful");
            }
        }
        else {
            fail("Inserting for deletion failed");
        }
    }


    @Test
    public void testFindWithPreQuery() throws Exception {

    }
}
